package com.min.redis.common.enums.base;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 全局错误码
 */
@Getter
@AllArgsConstructor
public enum ErrorCodeEnum {

    /**
     * 公共错误码
     * 0001-1000
     */
    PARAM_ILLEGAL(0001, "参数非法"),
    SYSTEM_ERROR(0002, "系统异常"),
    INNER_DATA_ERROR(0003, "内部数据异常"),
    OUTER_DATA_ERROR(0004, "外部依赖数据异常"),
    DEPENDENCY_SERVICE_ERROR(0005, "外部依赖服务异常"),
    TASK_CONCURRENCY_EXCEED(103, "任务并发超过上限"),
    DATA_NOT_EXIST(0006, "数据不存在"),
    REPEAT_REQUEST(0007, "重复请求");


    private final Integer code;

    private final String msg;

    public static ErrorCodeEnum of(Integer code) {
        if (code == null) {
            return null;
        }
        for (ErrorCodeEnum value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return null;
    }
}
